package com.ruoyi.technician.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.technician.domain.TechnicianTime;
import com.ruoyi.technician.service.ITechnicianTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 时间管理Controller
 *
 * @author ruoyi
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/technicianTime/technicianTime")
public class TechnicianTimeController extends BaseController {
    @Autowired
    private ITechnicianTimeService technicianTimeService;

    /**
     * 查询时间管理列表
     */
    @PreAuthorize("@ss.hasPermi('technicianTime:technicianTime:list')")
    @GetMapping("/list")
    public TableDataInfo list(TechnicianTime technicianTime) {
        startPage();
        List<TechnicianTime> list = technicianTimeService.selectTechnicianTimeList(technicianTime);
        return getDataTable(list);
    }

    /**
     * 导出时间管理列表
     */
    @PreAuthorize("@ss.hasPermi('technicianTime:technicianTime:export')")
    @Log(title = "时间管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TechnicianTime technicianTime) {
        List<TechnicianTime> list = technicianTimeService.selectTechnicianTimeList(technicianTime);
        ExcelUtil<TechnicianTime> util = new ExcelUtil<TechnicianTime>(TechnicianTime.class);
        util.exportExcel(response, list, "时间管理数据");
    }

    /**
     * 获取时间管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('technicianTime:technicianTime:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(technicianTimeService.selectTechnicianTimeById(id));
    }

    /**
     * 新增时间管理
     */
    @PreAuthorize("@ss.hasPermi('technicianTime:technicianTime:add')")
    @Log(title = "时间管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TechnicianTime technicianTime) {
        return toAjax(technicianTimeService.insertTechnicianTime(technicianTime));
    }

    /**
     * 修改时间管理
     */
    @PreAuthorize("@ss.hasPermi('technicianTime:technicianTime:edit')")
    @Log(title = "时间管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TechnicianTime technicianTime) {
        return toAjax(technicianTimeService.updateTechnicianTime(technicianTime));
    }

    /**
     * 删除时间管理
     */
    @PreAuthorize("@ss.hasPermi('technicianTime:technicianTime:remove')")
    @Log(title = "时间管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(technicianTimeService.deleteTechnicianTimeByIds(ids));
    }
}
